package com.a3dweijing.wetouch2.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;

import com.a3dweijing.wetouch2.Common.listview.CommonListviewAdapter;
import com.a3dweijing.wetouch2.Common.listview.ViewHolderListview;
import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.Util.GlideUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2018/3/23.
 */

public class ShoppingDetailsFragment extends Fragment
{
    View view;
    
    MyAdapter adapter;
    
    @BindView(R.id.listview)
    ListView listview;
    
    Unbinder unbinder;
    
    private ArrayList<String> list;


    @Nullable
    @Override
    public View getView() {
        return view;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState)
    {
        view = inflater.inflate(R.layout.shoppingdetailsfragment, container, false);

        Bundle arguments = getArguments();
        list = arguments.getStringArrayList("list");
        unbinder = ButterKnife.bind(this, view);
        initView();
        return view;
    }
    
    private void initView()
    {
        if (adapter == null)
        {
            adapter = new MyAdapter(getActivity(), list, R.layout.shoppingdetailsfragment_item);
            listview.setAdapter(adapter);
        }
    }
    
    class MyAdapter extends CommonListviewAdapter<String>
    {
        public MyAdapter(Context context, List<String> list, int layoutId)
        {
            super(context, list, layoutId);
        }
        
        @Override
        public void convert(ViewHolderListview holder, String s,int i)
        {
            ImageView view = holder.getView(R.id.imageview);
            GlideUtil.getInstance().showAutoImage(getActivity(), s, view);
        }
    }
    
    @Override
    public void onDestroyView()
    {
        super.onDestroyView();
        unbinder.unbind();
    }
}
